package com.xsm.ppsecret.util;

import com.google.gson.Gson;

/**
 * Author: Xiasem
 * Email: xiasem@163.com
 * Date: 17-4-18.
 */

public class JsonUtils {

    private static Gson mGson = new Gson();

    private static final JsonUtils jsonUtils = new JsonUtils();

    private JsonUtils() {}

    public static JsonUtils getInstance() {
        return jsonUtils;
    }

    /**
     * 将实体对象转换为json字符串
     * @param object
     * @param <T>
     * @return json字符串
     */
    public <T> String serialize(T object) {
        return mGson.toJson(object);
    }

    /**
     * 将json字符串转换为实体对象
     * @param json json字符串
     * @param clazz
     * @param <T>
     * @return
     */
    public <T> T deserialize(String json, Class<T> clazz) {
        return mGson.fromJson(json, clazz);
    }

}
